/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// The Cangjie API is in Beta. For details on its capabilities and limitations, please refer to the README file of the relevant cangjie wrapper repository.

package ohos.callback_invoke
import ohos.business_exception.BusinessException
import ohos.labels.APILevel

/**
 * Callback type.
 */
public type Callback<T> = (arg: T) -> Unit

/**
 * The callback wrapper base class.
 */
@!APILevel[
    since: "22"
]
public abstract class CallbackObject {
}


/**
 * The wrapper of callback without argument and returns.
 */
@!APILevel[
    since: "22"
]
public abstract class Callback0Argument <: CallbackObject {
    /**
     * invoker mainly for C.
     *
     * @param { ?BusinessException } err - indicates the callback params information.
     */
    @!APILevel[
        since: "22"
    ]
    public open func invoke(err: ?BusinessException): Unit
}


/**
 * The wrapper of callback with one argument and no returns.
 */
@!APILevel[
    since: "22"
]
public abstract class Callback1Argument<A> <: CallbackObject {
    /**
     * invoker mainly for C.
     *
     * @param { ?BusinessException } err - indicates the BusinessException error information.
     * @param { A } arg - indicates the callback params information A.
     */
    @!APILevel[
        since: "22"
    ]
    public open func invoke(err: ?BusinessException, arg: A): Unit
}


/**
 * The wrapper of callback with 2 arguments and no returns.
 */
@!APILevel[
    since: "22"
]
public abstract class Callback2Argument<A, B> <: CallbackObject {
    /**
     * invoker mainly for C.
     *
     * @param { ?BusinessException } err - indicates the BusinessException error information.
     * @param { A } arg1 - indicates the callback params information A.
     * @param { B } arg2 - indicates the callback params information B.
     */
    @!APILevel[
        since: "22"
    ]
    public open func invoke(err: ?BusinessException, arg1: A, arg2: B): Unit
}


/**
 * The wrapper of callback with 3 arguments.
 */
@!APILevel[
    since: "22"
]
public abstract class Callback3ArgumentWithReturn<A, B, C, D> <: CallbackObject {
    /**
     * invoker mainly for C.
     *
     * @param { ?BusinessException } err - indicates the BusinessException error information.
     * @param { A } arg1 - indicates the callback params information A.
     * @param { B } arg2 - indicates the callback params information B.
     * @param { C } arg3 - indicates the callback params information C.
     * @returns { D } the representation of the callback result.
     */
    @!APILevel[
        since: "22"
    ]
    public open func invoke(err: ?BusinessException, arg1: A, arg2: B, arg3: C): D
}


/**
 * The wrapper of callback with 2 arguments and returns.
 */
@!APILevel[
    since: "22"
]
public abstract class Callback1ArgumentWithReturn<A, B> <: CallbackObject {
    /**
     * invoker mainly for C.
     *
     * @param { ?BusinessException } err - indicates the BusinessException error information.
     * @param { A } arg1 - indicates the callback params information A.
     * @returns { B } the representation of the callback result.
     */
    @!APILevel[
        since: "22"
    ]
    public open func invoke(err: ?BusinessException, arg1: A): B
}


/**
 * The wrapper of callback without argument and returns.
 */
@!APILevel[
    since: "22"
]
public abstract class CallbackWithReturn<A> <: CallbackObject {
    /**
     * invoker mainly for C.
     *
     * @param { ?BusinessException } err - indicates the BusinessException error information.
     * @returns { A } the representation of the callback result.
     */
    @!APILevel[
        since: "22"
    ]
    public open func invoke(err: ?BusinessException): A
}


